home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / audio / midi / ptest.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.1 KB  |  89 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include "parse.h"
  18. #include <stdio.h>
  19. #include <unistd.h>
  20. #include <midi.h>
  21. #include <midiio.h>
  22.  
  23. void noteon(MIevent ev, void*, int)
  24. {
  25.     MImessage m = MESSAGE(ev);
  26.     
  27.     printf("note on: %d: [0x%x, 0x%x]\n", m.channel(), m.byte1(), m.byte2());
  28. }
  29.  
  30. void noteoff(MIevent ev, void*, int)
  31. {
  32.     MImessage m = MESSAGE(ev);
  33.     
  34.     printf("note off: %d: [0x%x, 0x%x]\n", m.channel(), m.byte1(), m.byte2());
  35. }
  36.  
  37. void control(MIevent ev, void*, int)
  38. {
  39.     MImessage m = MESSAGE(ev);
  40.     
  41.     printf("control: %d: [0x%x, 0x%x]\n", m.channel(), m.byte1(), m.byte2());
  42. }
  43.  
  44. void pressure(MIevent ev, void*, int)
  45. {
  46.     MImessage m = MESSAGE(ev);
  47.     
  48.     printf("pressure: %d: [0x%x, 0x%x]\n", m.channel(), m.byte1(), m.byte2());
  49. }
  50.  
  51.  
  52. main()
  53. {
  54.     miParser p;
  55.     MIport port;  
  56.     MIevent e;
  57.     MIconfig c;
  58.     u_int pbuf[2];
  59.  
  60.     pbuf[0] = MI_STAMPING;
  61.     pbuf[1] = MIRELSTAMP;
  62.     c.setparams(pbuf,2);
  63.  
  64.     p.changeCallBack(MIDI_NoteOn, (miCallBack) noteon, 0, 0);
  65.     p.changeCallBack(MIDI_NoteOff, (miCallBack) noteoff, 0, 0);
  66.     p.changeCallBack(MIDI_ControlChange, (miCallBack) control, 0, 0);
  67.     p.changeCallBack(MIDI_ChannelPressure, (miCallBack) pressure, 0, 0);
  68.     
  69.     if (port.open("rw", &c) < 0) {
  70.     exit(-1);
  71.     }
  72.  
  73.     port.setstart(0);
  74.     
  75.     while (1) {
  76.     int retval;
  77.     
  78.     if ((retval = port.receive(&e,1)) < 0)  // receive 1 event 
  79.     {
  80.         exit(-1);
  81.     }
  82.  
  83.     p.Parse(e);
  84.     
  85.     if (retval > 0)
  86.         retval = port.send(&e, retval);
  87.     }
  88. }
  89.